import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/',
    component: () => import('@/page/home.vue'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/error',
    component: () => import('@/views/LongOutErr'),
    hidden: true
  },

  // my self page out
  {
    path: '/home',
    component: () => import('@/page/home.vue'),
    hidden: true
  },
  {
    path: '/vue3',
    component: () => import('@/page/vue3.vue'),
    hidden: true
  },
  {
    path: '/pinia',
    component: () => import('@/page/pinia.vue'),
    hidden: true
  },
  {
    path: '/tuniao',
    component: () => import('@/page/tuniao.vue'),
    hidden: true
  },
  {
    path: '/element-plus',
    component: () => import('@/page/element-plus.vue'),
    hidden: true
  },
  {
    path: '/planet',
    component: () => import('@/page/element-plus.vue'),
    hidden: true
  },
  {
    path: '/about',
    component: () => import('@/page/about.vue'),
    hidden: true
  },
  {
    path: '/privacy',
    component: () => import('@/page/privacy.vue'),
    hidden: true
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  mode: 'history',
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
